package com.easy.base.utils;

import java.util.Random;

public class VerifyCodeUtil {
    /** 登录验证码前缀 */
    private static final String PREFIX_LOGIN_VERIFY_CODE_KEY = "loginVerifyCode_";

    /**
     * codeSequence 表示字符允许出现的序列值
     */
    private static char[] codeSequence = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    
    /**
     * 生成验证码字符串
     */
    public static String Generator() {
        Random random = new Random();
        StringBuilder randomCode = new StringBuilder();
        for(int i = 0; i < 4; i++) {
            String strRand = String.valueOf(codeSequence[random.nextInt(36)]);
            randomCode.append(strRand);
        }
        return randomCode.toString();
    }

    /**
     * Login verify code session key
     */
    public static String LoginVerifyCodeKey() {
        return PREFIX_LOGIN_VERIFY_CODE_KEY;
    }
}
